home *** CD-ROM | disk | FTP | other *** search
- Subject: Re: Saving weak refs. to other parts
- Sent: 9/18/96 10:11 AM
- Received: 9/18/96 10:11 AM
- From: kswenson@keypress.com (Kirk Swenson)
- Reply-To: ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List
-
-
- >We are making a suite of parts that can be connected to each other in
- >various ways by the users. The connections is used in a "run-time" mode of
- >the document to send messages between the parts (using extensions).
- >
- >I have been trying to figure out how to make this connetions persistent (the
- >users do not want to reconnect all the parts each time the document is
- >opened). I have found a solution that will save the references (using the
- >weak reference to the other parts storage unit) that work when I do a normal
- >save of the document.
- >
- >My problems start when I want this to function also during various cloning
- >operations (i.e. "Save a copy"). I am using ODF for this work, but I think
- >this is partly an ODF and partly an OD problem.
-
- We faced the same problem a while back, and had to work through the same
- issues. I had intended to send a note to the list about it but got
- sidetracked. Your message reminded me, so here it is.
-
- >1. ODFs handling of CloneInto for non-embedding parts simply externalizes
- >the content, and though there are parameters for cloning info it does not
- >use them. Of course, I can override FW_Parts CloneInto and make a sollution
- >like for embedding parts. But is there any specific reason why the default
- >FW_Part behavior is different from the embedding parts?
-
- I use the FW_CEmbeddingPart::CloneInto override for all of my parts,
- embedding or not. Suggestion to the ODF team: The clone information is
- useful for other reasons than embedding. I would like to see it forwarded
- to all parts, not just non-embedding parts. In other words,
- FW_CEmbeddingPart::CloneInto could be moved to FW_CPart, and then all parts
- would have access to the clone info.
-
- >2. This one is my -real- problem. During a cloning operation, I suppose that
- >the right thing to do with my connected parts, is to use WeakClone. The
- >documentation tells me that WeakClone will return an ID that I can use to
- >get a weak reference -after- the cloning operation is finished; that is
- >after EndClone if I understand it right. If my part started the cloning
- >operation, this would be OK. But what happens in case of "Save as..." or if
- >there is clipboard operation that invloves my part, but that was made from a
- >part my part is embedded in? Possibly I have overlooked some detail here,
- >but what I seem to miss is some sort of "PostClone" operation that lets my
- >part check if the ID from WeakClone is valid after the cloning, and saves
- >either the weak reference or a "NULL-tag" of some sort together with my
- >"normal" content data.
-
- I have posted code at the end of this message that seems to be working for
- me. As you suggested, the crux of the matter is using WeakClone when
- cloning. Suggestion to the ODF team: FW_CCloneInfo has methods for cloning
- strong references. It seems like an appropriate place to add methods for
- cloning weak references as well. The code posted below would be simplified
- substantially with the addition of such a method, and it would be one less
- wheel for others to reinvent.
-
- Kirk Swenson
- Senior Software Engineer
- Key Curriculum Press
- kswenson@keypress.com
-
- ------------------------------------------------------------------------------
- Here's the code. Note that it doesn't seem to be possible to write out a
- null reference, so the presence or absence of a reference must be indicated
- separately.
-
- void
- KCP_CODPersistentReference::
- WriteWeakReference(
- Environment* ev,
- FW_CWritableStream& ioWriteStream,
- ODStorageUnit* ioDestSU,
- FW_CCloneInfo* iCloneInfo) const
- {
- FW_ASSERT( mPersistentID != kODNULLID);
-
- // If we are not cloning, we can just write out a reference to the
- // persistent ID we already have.
- ODID tIDToWrite = mPersistentID;
- ODStorageUnitRef tWeakReference;
-
- // If we are cloning, then we need to translate our part ID into
- // the correct ID for the newly cloned storage unit.
- if( iCloneInfo != nil) {
-
- ODDraft* tFromDraft = iCloneInfo->GetFromDraft( ev);
- FW_ASSERT( tFromDraft != nil);
-
- FW_CFrame* tScopeFrame = iCloneInfo->GetScopeFrame( ev);
- FW_ASSERT( tScopeFrame != nil);
-
- ODID tScopeFrameID = tScopeFrame->GetID( ev);
-
- tIDToWrite = tFromDraft->WeakClone(
- ev,
- iCloneInfo->GetDraftKey( ev),
- tIDToWrite,
- kODNULLID,
- tScopeFrameID);
-
- FW_ASSERT( tIDToWrite != kODNULLID);
- }
-
- // Convert the ID to a weak storage unit reference.
- ioDestSU->GetWeakStorageUnitRef( ev, tIDToWrite, tWeakReference);
-
- // Write out the weak storage unit reference
- ioWriteStream.Write( &tWeakReference, sizeof( tWeakReference));
- }